﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Configuration;
using SimpleMVC;

namespace SimpleMVC.Filters
{
    public class ThemeFilter:IResultFilter
    {
        public void OnResultExecuted(ResultExecutedContext filterContext)
        {

        }

        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            var theme = ConfigurationManager.AppSettings["Theme"] ?? "Default";
            ThemeBundles themeBundles = null;
            if (BundleConfig.AllThemeBundles.TryGetValue(theme, out themeBundles))
            {
                if (themeBundles.ThemeCsses != null && themeBundles.ThemeCsses.Count > 0)
                {
                    filterContext.Controller.ViewBag.ThemeCsses = themeBundles.ThemeCsses;
                }
                if (themeBundles.ThemeScipts != null && themeBundles.ThemeScipts.Count > 0)
                {
                    filterContext.Controller.ViewBag.ThemeScipts = themeBundles.ThemeCsses;
                }
            }
        }
    }
}